<template>
	<view>
		<!-- <view class="" style="height: 70upx;background-color: #fff;display: flex;justify-content: space-around;line-height: 70upx;">
			<text :class="{active:isActive}" @click="Aclick">美购资讯</text>
			<text :class="{active:isActive1}" @click="Aclick">我的消息</text>
		</view> -->
		<!-- <view class="" v-if="isActive1">
			<view class="notice-item">
				<text class="time">11:30</text>
				<view class="content">
					<text class="title">欢迎加入生物伞美购商城</text>
					<text class="introduce">欢迎加入生物伞美购商城</text>
					<view class="" style="text-align: right;">
						<text>查看详情</text>
						<text class="more-icon yticon icon-you"></text>
					</view>
				</view>
			</view>
		</view> -->
		<view class="" v-if="isActive">
			
			<view class="notice-item" v-for="(item,i) in res" :key="i">
				<text class="time">{{item.create_time}}</text>
				<view class="content">
					<text class="title">{{item.title}}</text>
					<view class="img-wrapper">
						<image class="pic" :src="'https://cx.mingmeijt.com' + item.image_thumb"></image>
						<!-- <view class="cover">
							活动结束
						</view> -->
					</view>
					<text class="introduce">{{item.content}}</text>
					<view class="bot b-t" @click="todetail(item.id)">
						<text>查看详情</text>
						<text class="more-icon yticon icon-you"></text>
					</view>
				</view>
			</view>
			
		</view>
		
		<uni-load-more :loadingType="loadingType" :contentText="contentText"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				isActive: true,
				isActive1: false,
				res:[],
				user_id:'',	
				
				loadingText: '加载中...',
				loadingType: 0,
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				page: 1,
				timer:{},
			}
		},
		onLoad: function () {
			uni.showLoading()
			uni.getStorage({
				key: 'user_id',
				success: (res) => {
					this.user_id = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../../index/index'
					});
				}
			});
		},
		onPullDownRefresh() {
			this.page = 1
			this.loadingType = 0;//将loadingType归0重置
			this.setAjax()
			setTimeout(function () {
					uni.stopPullDownRefresh();
			}, 1000);
		},
		// 上拉加载
		onReachBottom(){
			if (this.timer != null) {
				clearTimeout(this.timer)
			}
			this.timer = setTimeout(()=> {
				this.getmorenews()
			}, 1000);
		},
		methods: {
			setAjax(){
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/News/index?p=1',
					method: 'POST',
					data:{
						user_id: this.user_id,
						session_id: uni.getStorageSync("sessionid")
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if(res.data.code == 998){
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}
						this.res = res.data.data.list
					},
					fail: () => {},
					complete: () => {}
				});
				uni.hideLoading()
			},
			getmorenews() {
				let o = this
				this.page++;//每触底一次 page +1
				if (this.loadingType !== 0) {//loadingType!=0;直接返回
					return false;
				}
				this.loadingType = 1;
				uni.showNavigationBarLoading();//显示加载动画
				uni.request({
					url:'https://cx.mingmeijt.com/Api/News/index?p=' + this.page,
					method: 'POST',
					data: {
						user_id: this.user_id,
						session_id: uni.getStorageSync("sessionid")
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: function(res) {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if (res.data.data.list == '' || res.data.data.list == null) {//没有数据
							o.loadingType = 2;
							uni.hideNavigationBarLoading();//关闭加载动画
							return;
						}
						var tpcList = res.data.data.list
						o.res = o.res.concat(tpcList);//将数据拼接在一起
						o.loadingType = 0;//将loadingType归0重置
						uni.hideNavigationBarLoading();//关闭加载动画
					}
				});
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
			todetail(id) {
				uni.navigateTo({
					url: './notice_details?id=' + id
				})
			},
			Aclick(){
				this.isActive = !this.isActive
				this.isActive1 = !this.isActive1
			},
			
		}
	}
</script>

<style lang='scss'>
	page {
		background-color: #f7f7f7;
		padding-bottom: 30upx;
	}
	.active {
		 border-bottom: 5upx solid #000;
		 color: #000;
		 }
	.notice-item {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.time {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 80upx;
		padding-top: 10upx;
		font-size: 26upx;
		color: #7d7d7d;
	}

	.content {
		width: 710upx;
		padding: 0 24upx;
		background-color: #fff;
		border-radius: 4upx;
	}

	.title {
		display: flex;
		align-items: center;
		height: 90upx;
		font-size: 32upx;
		color: #303133;
	}

	.img-wrapper {
		width: 100%;
		height: 260upx;
		position: relative;
	}

	.pic {
		display: block;
		width: 100%;
		height: 100%;
		border-radius: 6upx;
	}

	.cover {
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, .5);
		font-size: 36upx;
		color: #fff;
	}

	.introduce {
		display: inline-block;
		padding: 16upx 0;
		font-size: 28upx;
		color: #606266;
		line-height: 38upx;
	}

	.bot {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 80upx;
		font-size: 24upx;
		color: #707070;
		position: relative;
	}

	.more-icon {
		font-size: 32upx;
	}
</style>
